﻿@model S4Store.Models.AfterSaleReport.AfterSaleCarModelHistoryModel
@{
    Layout = null;

    //公式部分
    List<dynamic> 事故车产值 = new List<dynamic>();
    List<dynamic> 事故车产值完成率 = new List<dynamic>();
    List<dynamic> 平均单车产值 = new List<dynamic>();
    string carbrandname = string.Empty;
    if(Model.CTDays.Count>0)
    {
        carbrandname = Model.CTDays[0].CarBrand.Name;
    }
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {

        var query = Model.CTDays.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        事故车产值.Add(new
        {
            时间 = dt,
            事故车产值 = query.Sum(o => o.SGCCZ_AccidentCarValue)
        });

        事故车产值完成率.Add(new
        {
            时间 = dt,
            事故车产值完成率 = Model.CTMonths.Where(o => o.Month.Year == dt.Year && o.Month.Month == dt.Month).Sum(o => o.BYSGCCZBM_MonthAacidentCarTargetValue) == 0 ? 0 : query.Sum(o => o.SGCCZ_AccidentCarValue) / Model.CTMonths.Where(o => o.Month.Year == dt.Year && o.Month.Month == dt.Month).Sum(o => o.BYSGCCZBM_MonthAacidentCarTargetValue)
        });

        平均单车产值.Add(new
        {
            时间 = dt,
            平均单车产值 = query.Sum(o=>o.SGRCTC_AccidentCarToFactory+o.WXRCTC_MaintainCarToFactory+o.WKBYS_Maintain5KNum+o.SQBYS_Maintain10KNum)==0?0:query.Sum(o => o.WQBYCZ_Maintain5KValue + o.SQBYCZ_Maintain10KValue + o.QTWXCZ_MaintainOtherValue+o.SGCCZ_AccidentCarValue)/query.Sum(o=>o.SGRCTC_AccidentCarToFactory+o.WXRCTC_MaintainCarToFactory+o.WKBYS_Maintain5KNum+o.SQBYS_Maintain10KNum)
        });
        
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.IsRate = false;
    ChartModel.YAxis = "事故车产值";

    foreach (var item in 事故车产值.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "事故车产值";
    foreach (var item in 事故车产值)
    {
        series.Data.Add(item.事故车产值);
    }
    ChartModel.Serieses.Add(series);
    
    //S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    //series1.Name = "实际5K保养完成率";
    //foreach (var item in _5K保养完成率)
    //{
    //    series1.Data.Add(item._5K保养完成率实际);
    //}
    //ChartModel.Serieses.Add(series1);


    //2
    S4Store.Models.Chart.Line ChartModel1 = new S4Store.Models.Chart.Line();
    ChartModel1.IsRate = true;
    ChartModel1.YAxis = "事故车产值完成率";

    foreach (var item in 事故车产值完成率.GroupBy(o => o.时间))
    {
        ChartModel1.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11 = new S4Store.Models.Chart.ChartSeries();
    series11.Name = "事故车产值完成率";
    foreach (var item in 事故车产值完成率)
    {
        series11.Data.Add(item.事故车产值完成率*100);
    }
    ChartModel1.Serieses.Add(series11);

    //S4Store.Models.Chart.ChartSeries series12 = new S4Store.Models.Chart.ChartSeries();
    //series12.Name = "10K保养完成率实际";
    //foreach (var item in _10K保养完成率)
    //{
    //    series12.Data.Add(item._10K保养完成率实际);
    //}
    //ChartModel1.Serieses.Add(series12);



    
    
    //3
    S4Store.Models.Chart.Line ChartModel3 = new S4Store.Models.Chart.Line();
    ChartModel3.IsRate = false;
    ChartModel3.YAxis = "平均单车产值";

    foreach (var item in 平均单车产值.GroupBy(o => o.时间))
    {
        ChartModel3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31 = new S4Store.Models.Chart.ChartSeries();
    series31.Name = "平均单车产值";
    foreach (var item in 平均单车产值)
    {
        series31.Data.Add(item.平均单车产值);
    }
    ChartModel3.Serieses.Add(series31);

    //S4Store.Models.Chart.ChartSeries series32 = new S4Store.Models.Chart.ChartSeries();
    //series32.Name = "实际维修入场台次完成率";
    //foreach (var item in 维修入场台次完成率)
    //{
    //    series32.Data.Add(item.实际维修入场台次完成率);
    //}
    //ChartModel3.Serieses.Add(series32);

<div style="height:100%; overflow:auto">
@Html.Action("ReportBar", "Common", Model.BarModel)
@*<div class="pagetitle">@(carbrandname)入厂台次过程KPI历史数据查询</div>*@
<div class="pageContent">
	
	<div class="tabs" currentIndex="0" eventType="click">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li><a href="javascript:;"><span>事故车产值</span></a></li>
					<li><a href="javascript:;"><span>事故车产值完成率</span></a></li>
					<li><a href="javascript:;"><span>平均单车产值</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" >
			<div>
            @Html.Partial("../Chart/Line", ChartModel)
			</div>
			<div>
            @Html.Partial("../Chart/Line", ChartModel1)
			</div>
            <div>
            @Html.Partial("../Chart/Line", ChartModel3)
			</div>
		</div>
		<div class="tabsFooter">
			<div class="tabsFooterContent"></div>
		</div>
	</div>
</div>

</div>
}